/* Copyright (c) 2008 Google Inc. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Text;

using Google.GCalExchangeSync.Library.Util;
using Google.GCalExchangeSync.Library.WebDav;

using TZ4Net;
using log4net;

namespace Google.GCalExchangeSync.Library
{
    /// <summary>
    /// Collection class for appointment
    /// </summary>
    public class AppointmentCollection : Dictionary<DateTimeRange, List<Appointment>>
    {
        /// <summary>
        /// Add an appointment to the collection
        /// </summary>
        /// <param name="a">The appointment to add</param>
        public void Add(Appointment a)
        {
            DateTimeRange r = a.Range;
            if (!this.ContainsKey(r))
            {
                this[r] = new List<Appointment>();
            }

            this[r].Add(a);
        }

        /// <summary>
        /// Get the set of appointments from the collection
        /// with the matching date time range.
        /// </summary>
        /// <param name="r">DateRange to match against</param>
        /// <returns>The set of appointments with matching range</returns>
        public List<Appointment> Get(DateTimeRange r)
        {
            return this.ContainsKey(r) ?
                this[r] : new List<Appointment>();
        }
    }

    /// <summary>
    /// A collection of free busy events and appointments
    /// </summary>
    public class FreeBusyCollection : Dictionary<DateTime, FreeBusyTimeBlock>
    {
        private AppointmentCollection appointments;

        /// <summary>
        /// Appointments associated with the Free Busyevents
        /// </summary>
        public AppointmentCollection Appointments
        {
            get { return this.appointments; }
        }

        /// <summary>
        /// Create a new Free Busy Collection
        /// </summary>
        public FreeBusyCollection() : base()
        {
            this.appointments = new AppointmentCollection();
        }
    }
}
